import request from '@/util/request'
import md5 from 'js-md5'

export function changeAvatar(data) {
  return request({
    url: 'personalCenter/avatar.json',
    method: 'PATCH',
    headers: { 'Content-Type': 'multipart/form-data' },
    data,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function changeUserNick(nickName) {
  return request({
    url: `personalCenter/nickName/${nickName}.json`,
    method: 'patch',
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function checkPassword(userPassword) {
  return request({
    url: 'personalCenter/checkPassword.json',
    headers: { userPassword: md5(userPassword) },
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function changePassword(uuid, userPassword) {
  return request({
    url: `personalCenter/changePassword/${uuid}.json`,
    headers: { userPassword: md5(userPassword) },
    method: 'patch',
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function beforeChangePhone(headers) {
  return request({
    url: 'personalCenter/beforeChangePhone.json',
    method: 'get',
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function beforeChangePhoneCheck(headers, code) {
  return request({
    url: `personalCenter/beforeChangePhone/${code}.json`,
    method: 'get',
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function checkUserPhone(userPhone) {
  return request({
    url: 'personalCenter/checkUserPhone.json',
    method: 'get',
    params: { userPhone },
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function mobileChange(headers, code) {
  return request({
    url: `code/mobileChange/${code}.json`,
    method: 'get',
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function changePhone(headers, code) {
  return request({
    url: `personalCenter/changePhone/${code}.json`,
    method: 'patch',
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}
